package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.pojo.Setmeal;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface SetMealMapper {
    /**
     * 根据id查询套餐
     * @param id
     * @return
     */
    @Select("select * from t_setmeal where id = #{id}")
    Setmeal findById(Integer id);

    /**
     * 新增体检套餐
     * @param setmeal
     * @return
     */
    @Insert("insert into t_setmeal(name, code, helpCode, sex, age, price, remark, attention, img) value(#{name},#{code},#{helpCode},#{sex},#{age},#{price},#{remark},#{attention},#{img}) ")
    boolean add(Setmeal setmeal);
@Insert("insert into  t_setmeal_checkgroup(setmeal_id, checkgroup_id)  value(#{id},#{i})")
    void addGroupIdInSetmeal(int id, int i);

    /**
     * 编辑
     * @param setmeal
     * @return
     */
    @Update("update t_setmeal set name =#{name},code=#{code},helpCode=#{helpCode},sex=#{sex},age=#{age},price=#{price},remark=#{remark},attention=#{attention},img=#{img} where id = #{id}")
    boolean edit(Setmeal setmeal);

    /**
     * 更新对应的Meal和Group的组
     * @param originGroupId
     * @param setMealId
     * @param GroupId
     */
    @Update("update t_setmeal_checkgroup set checkgroup_id =#{GroupId} where setmeal_id = #{setMealId} and checkgroup_id =#{originGroupId}")
    void editSetMealInGroup(int originGroupId, Integer setMealId,int GroupId);

    /**
     * 删除多余的对应setMealId
     * @param checkGroupId
     * @param setMealId
     */
    @Delete("delete from t_setmeal_checkgroup where checkgroup_id = #{checkGroupId} and setmeal_id = #{setMealId}")
    void delete(Integer checkGroupId,Integer setMealId);
    /**
     * 增加对应的setMeal
     * @param checkGroupId
     * @param setMealId
     */
    @Insert("insert into t_setmeal_checkgroup(setmeal_id, checkgroup_id) value (#{setMealId},#{checkGroupId})")
    void insert(Integer checkGroupId,Integer setMealId);

    /**
     * 查询所有套餐
     * @return
     */
    @Select("select * from t_setmeal")
    List<Setmeal> findAll();
    //获取照片所有路径
    @Select("select img from t_setmeal")
    List<String> FindImgs();
    @Insert("   insert into t_setmeal_checkgroup(setmeal_id, checkgroup_id)\n" +
            "        VALUES(#{setmealId},#{checkgroupId})")
    void addCheckGroupAndSetmeal(Map<String, Integer> map);
}
